Skip to content

test: Deflake adaptive statistics and browser plugin tests on slow CI runners - #2203

Merged
vdusek merged 1 commit into
masterfrom
test/deflake-adaptive-stats-and-goto
Sep 4, 2026
Merged

test: Deflake adaptive statistics and browser plugin tests on slow CI runners#2203
vdusek merged 1 commit into
masterfrom
test/deflake-adaptive-stats-and-goto

Conversation

@vdusek

@vdusek vdusek commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Two unit tests flake on the Windows CI shard under parallel load (example run):

  • test_adaptive_crawling_statistics asserts each adaptive counter equals exactly 1, but when a slow Chromium launch pushes the browser sub-crawl past the default 60s request_handler_timeout, BasicCrawler retries the request - correct behavior - and every counter increments again (assert 2 == 1). The test now passes a 5-minute request_handler_timeout, removing the retry trigger while keeping the exact-count assertions, so a real double-counting regression still fails it.
  • test_new_browser ran page.goto with Playwright's default 30s timeout, which the first navigation on a saturated runner can exceed. Raised to 60s, matching test_browser_pool.py.

Verified with deterministic fault injection: a 70s stall in BrowserPool.new_page reproduced the exact CI failure before the fix and 0/3 failures after; a 40s-slow server reproduced the goto timeout with the default and passed with 60s. Plus 0/30 failures re-running both modules under pytest -n auto. No production code is touched.

✍️ Drafted by Claude Code

@vdusek vdusek added t-tooling Issues with this label are in the ownership of the tooling team. adhoc Ad-hoc unplanned task added during the sprint. labels Aug 31, 2026
@vdusek vdusek self-assigned this Aug 31, 2026
@github-actions github-actions Bot added this to the 148th sprint - Tooling team milestone Aug 31, 2026
@github-actions github-actions Bot added the tested Temporary label used only programatically for some analytics. label Aug 31, 2026
@vdusek
vdusek requested a review from Pijukatel August 31, 2026 08:19
@vdusek
vdusek marked this pull request as ready for review August 31, 2026 08:19
@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.73%. Comparing base (ce8f615) to head (303f50a).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2203      +/-   ##
==========================================
- Coverage   93.73%   93.73%   -0.01%     
==========================================
  Files         181      181              
  Lines       12825    12852      +27     
==========================================
+ Hits        12022    12047      +25     
- Misses        803      805       +2     
Flag Coverage Δ
unit 93.73% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vdusek
vdusek merged commit d445359 into master Sep 4, 2026
36 checks passed
@vdusek
vdusek deleted the test/deflake-adaptive-stats-and-goto branch September 4, 2026 10:22
vdusek added a commit that referenced this pull request Sep 8, 2026
…2221)

Two adaptive crawler tests flake on the Windows CI shard for the same
reason. This supersedes #2207, which fixed one of them from a base that
predates #2203.

The browser sub crawler navigates under `PlaywrightCrawler`'s own
`navigation_timeout`, a 60s `SharedTimeout` shared by the
pre/post-navigation hooks and `goto`. That budget is separate from
`request_handler_timeout`, because `BasicCrawler` applies the handler
timeout only around the router call. So a cold Chromium launch on a
saturated runner can blow the navigation budget while the handler
timeout still has minutes left, and relaxing the handler timeout does
nothing about it.

- `test_adaptive_crawling_statistics` fails with `assert 3 == 1`
([example
run](https://github.com/apify/crawlee-python/actions/runs/34120120329/job/101736011265)).
When navigation exceeds the 60s budget, `BasicCrawler` retries the whole
request, which is correct behavior, and every adaptive counter
increments again. The failing run timed out twice before succeeding: 60
+ 60 + 17s matches its 146s crawler runtime. It now passes a 5 minute
`navigation_timeout`, the same ceiling #2203 already gave its handler.
- `test_adaptive_playwright_crawler_timeout_in_sub_crawler` fails with
`Expected 'browser_handler' to be called once. Called 0 times.`
([example
run](https://github.com/apify/crawlee-python/actions/runs/33467016711/job/99728873095)).
It sets `max_request_retries=0`, so one slow navigation fails the only
attempt before the handler ever runs. It now passes a 120s
`navigation_timeout`, matching the handler timeout it already relaxes.

Both keep their existing assertions, so a real double-counting or
missed-increment regression still fails them. Passing the key needs
`navigation_timeout` in `_PlaywrightCrawlerAdditionalOptions`;
`PlaywrightCrawler.__init__` already accepts it and `ty` reports
`invalid-key` without it.

Verified with deterministic fault injection in both cases. For the
statistics test, monkeypatching `Page.goto` to stall the first two
navigations by 70s reproduces the exact `assert 3 == 1` with two retries
under the 60s ceiling, and passes in 71s under the 5 minute one with all
counters at 1; plus 0 failures in 39 runs of that test alone and 31/31
for the whole file serially. For the sub crawler timeout test, a
playwright-only pre-navigation delay of 70s consumes the shared budget
and reproduces the CI failure under the default ceiling, passing under
120s, with 0/96 failures across 8 concurrent Chromium-saturated lanes
afterwards. The adaptive module passes under `-n auto` in 6 of 7 runs;
the exception hit an unrelated `Errno 98` in the uvicorn test server
fixture, caused by running several pytest processes at once locally.

*✍️ Drafted by Claude Code*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants